package com.livesource.client.web;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.livesource.client.LiveSourceGlobalVariables;
import com.livesource.client.utilities.LoadingPanel;
import com.livesource.client.web.sourceCode.ButtonRefresh;
import com.livesource.client.web.sourceCode.LiveDocumentationHelpIcon;
import com.livesource.client.web.sourceCode.filesTree.SourceFilesFiltersList;
import com.livesource.client.webservices.LoadProjectFiles;

/**
 * Show all the classes of the current project as a specification format.
 * 
 */
public class LiveSourcePage extends VerticalPanel {

	public static ScrollPanel featuresTreePanel = new ScrollPanel();
	public static VerticalPanel featureVisualizationPanel = new VerticalPanel();
	public static HorizontalPanel hpOptionsIcons = new HorizontalPanel();

	public LiveSourcePage(String selectedView) {

		this.setHeight("450px");

		this.add(hpTop(selectedView));

		HorizontalPanel hp = new HorizontalPanel();

		featuresTreePanel.setSize("320px", "100%");

		featuresTreePanel.clear();
		featuresTreePanel.add(new LoadingPanel());

		featuresTreePanel.setHeight("450px");

		hp.add(featuresTreePanel);

		hp.add(new HTML("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"));

		featureVisualizationPanel.clear();
		featureVisualizationPanel.setSize("100%", "100%");
		// featureVisualizationPanel.setSpacing(20);
		hp.add(featureVisualizationPanel);

		this.add(hp);
	}

	private HorizontalPanel hpTop(String selectedView) {

		HorizontalPanel hp = new HorizontalPanel();

		hp.setSpacing(20);

		hp.add(new SourceFilesFiltersList(selectedView));

		hpOptionsIcons.setWidth("400px");
		hpOptionsIcons
				.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		hp.add(hpOptionsIcons);

		hp.add(new ButtonRefresh(buttonRefreshClickHandler()));

		hp.add(new LiveDocumentationHelpIcon("LiveSourceWeb"));

		return hp;
	}

	private ClickHandler buttonRefreshClickHandler() {

		return (new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {

				LiveSourceGlobalVariables.projectEntries = null;

				new LoadProjectFiles();
			}
		});

	}

}
